module.exports = (function () {
    var express = require('express');
    var router = express.Router();
    var path = require('path');
    var config = require('./../config.json');
    var mailSend = require('./../service/mailSend.js');
    var request = require('request').defaults({
        json: true
    });
    router.get('/', function (req, res) {
        res.sendFile(path.join(__dirname, './authenticateViews/findPassword.html'));
    });
    router.post('/', function (req, res) {
        var postBody = req.body;
        request({
            url: config.adminBaseUrl + '/user/' + postBody.userName + '/userInfo'
        }, function (err, response, body) {
            if (!body) {
                res.json('无效的用户名!');
            }
            else if (body.mail === postBody.mail) {
                mailSend.sendPassword(body, body.mail);
                res.json('密码已发送到你的邮箱,请查收');
            } else {
                res.json('你的邮箱与注册时不符!');
            }

        });
    });
    return router;
})();
